import uniqueId from '@form-create/utils/lib/unique';
import { localeProps, makeRequiredRule } from '../../utils';

const label = '数字';
const name = 'jd-number';

export default {
    icon: 'icon-number',
    label,
    name,
    rule({ t }) {
        return {
            type: 'inputNumber',
            field: 'SZ',
            title: '数字',
            info: '',
            $required: false,
            validate: false,
            style: {
                width: '100%'
            },
            props: {
                controls: false,
                controlsPosition: 'right'
            }
        };
    },
    props(_, { t }) {
        return localeProps(t, name + '.props', [
            { type: 'input', field: 'placeholder', title: '占位文本' },
            makeRequiredRule(),
            {
                type: 'col',
                props: { span: 12 },
                children: [{ type: 'switch', field: 'controls', title: '隐藏控制', value: true, props: { activeValue: false, inactiveValue: true } }]
            },
            {
                type: 'col',
                props: { span: 12 },
                children: [{ type: 'switch', field: 'controlsPosition', title: '右侧显示', value: 'right', props: { activeValue: 'right', inactiveValue: 'default' } }]
            },
            {
                type: 'row',
                props: { gutter: 5 },
                children: [
                    {
                        type: 'col',
                        props: { span: 12 },
                        children: [
                            {
                                type: 'inputNumber',
                                field: 'max',
                                title: '最大值',
                                props: {},
                                inject: true,
                                on: {
                                    change(injectData, maxValue) {
                                        const minValue = injectData.$f.rule[4].children[1].children[0].value;
                                        if (minValue || minValue === 0) {
                                            if (maxValue < minValue) {
                                                injectData.self.props.min = minValue;
                                                injectData.self.modelValue = minValue;
                                                injectData.self.value = minValue;
                                                injectData.$f.activeRule.props.max = minValue;
                                            }
                                            // if (!injectData.$f.rule[4].children[1].children[0].props.max || injectData.$f.rule[4].children[1].children[0].props.max < maxValue) {
                                            injectData.$f.rule[4].children[1].children[0].props.max = maxValue;
                                            // }
                                        }
                                    }
                                }
                            }
                        ]
                    },
                    {
                        type: 'col',
                        props: { span: 12 },
                        children: [
                            {
                                type: 'inputNumber',
                                field: 'min',
                                title: '最小值',
                                inject: true,
                                props: {},
                                on: {
                                    change(injectData, minValue) {
                                        const maxValue = injectData.$f.rule[4].children[0].children[0].value;
                                        if (maxValue || maxValue === 0) {
                                            if (minValue >= maxValue) {
                                                injectData.self.props.max = maxValue;
                                                injectData.self.modelValue = maxValue;
                                                injectData.self.value = maxValue;
                                                injectData.$f.activeRule.props.min = maxValue;
                                            }
											injectData.$f.rule[4].children[0].children[0].props.min = minValue;
                                        }
                                    }
                                }
                            }
                        ]
                    },
                    {
                        type: 'col',
                        props: { span: 12 },
                        children: [{ type: 'inputNumber', field: 'step', title: '步长', props: { min: 1 } }]
                    }
                ]
            },
            {
                type: 'col',
                props: { span: 12 },
                children: [{ type: 'switch', field: 'disabled', title: '是否禁用' }]
            },
            {
                type: 'col',
                props: { span: 12 },
                children: [{ type: 'switch', field: 'readonly', title: '是否只读' }]
            }
        ]);
    }
};
